﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace CopyDirectory
{
    class Program
    {
        static void Main(string[] args)
        {
            Traverse(@"C:\Users\Academy\Documents\Visual Studio 2010\Projects\InputOutput\DirectorySearching", "New");

        }
        private static void Traverse(string path, string newDir)
        {
            Directory.CreateDirectory(newDir);
            //Console.WriteLine("[{0}]", path);
            string[] subdirs = Directory.GetDirectories(path);
            //List<string> differences = new List<string>();
            foreach (string subdir in subdirs)
            {
                StringBuilder builder = new StringBuilder();
                for (int i = subdir.Length - 1; subdir[i] != '\\'; i--)
                {
                    builder.Append(subdir[i]);
                }
                StringBuilder corrbuilder = new StringBuilder();
                for (int i = builder.Length-1; i >=0; i--)
                {
                    corrbuilder.Append(builder[i]);
                }
                // string subPath = builder;
                //differences.Add(path-subdir);
                string tempDir=newDir;
                newDir = newDir + @"\" + corrbuilder;
                Traverse(subdir, newDir);
                newDir = tempDir;
            }
            string[] files = Directory.GetFiles(path);
            foreach (string f in files)
            {
                StringBuilder builder = new StringBuilder();
                for (int i = f.Length - 1; f[i] != '\\'; i--)
                {
                    builder.Append(f[i]);
                }
                StringBuilder corrbuilder = new StringBuilder();
                for (int i = builder.Length - 1; i >= 0; i--)
                {
                    corrbuilder.Append(builder[i]);
                }
                File.Copy(f, newDir + @"\" + corrbuilder);
            }
        }


    }
}
